Configuração da tabela:
[ID_do_item_vendido] = {amount = quantidade, requires = {{ID_do_item_trocado, quantidade}, {ID_do_item_trocado, quantidade}, etc}},
Código:
local config = {
--[itemid] = {amount = x, requires = {{itemid, amount}, {itemid, amount}, ...}},
}
local options = ""
for sell, info in pairs(config) do
local itens_required = ""
for i = 1, #info.requires do
if itens_required == "" then
itens_required = info.requires[i][2].."x "..getItemNameById(info.requires[i][1])
else
itens_required = itens_required..(i == #info.requires and " and " or ", ")..info.requires[i][2].."x "..getItemNameById(info.requires[i][1])
end
end
options = options.."\n"..info.amount.."x "..getItemNameById(sell).." - "..itens_required
end
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "trade") or msgcontains(msg, "buy") then
selfSay("Hello. To see my offers, say {offers}; to buy something, tell me the item's name.", cid)
talkState[talkUser] = 1
elseif msgcontains(msg, "offers") and talkState[talkUser] == 1 then
doPlayerPopupFYI(cid, options)
talkState[talkUser] = 0
elseif talkState[talkUser] == 1 then
local item = config[getItemIdByName(msg)]
if not item then
selfSay("Sorry, I don't recognize this item. Try another one.")
return true
end
for i = 1, #item.requires do
if getPlayerItemCount(cid, item.requires[i][1]) < item.requires[i][2] then
selfSay("Sorry, you don't have "..item.requires[i][2].."x "..getItemNameById(item.requires[i][1])..".", cid)
talkState[talkUser] = 0
return true
end
end
selfSay("OK, here yours "..item.amount.."x "..getItemNameById(getItemIdByName(msg)).."!", cid)
for i = 1, #item.requires do
doPlayerRemoveItem(cid, item.requires[i][1], item.requires[i][2])
end
doPlayerAddItem(cid, getItemIdByName(msg), item.amount)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())






info
Grupo: Visconde
Registrado: 04/01/14
Posts: 320
Reputação: +15
Boa noite..
Estou precisando de um NPC que troque itens por outros, porem ele varia diversas trocas, por exemplo:
100 soul orbs - 100 infernalt bolt
10 life crystal = 1 flawless ice crystal
dragon lance + dragon shield + bart skirt = obsidian knife
Alguém poderia me ajudar??
Obrigado!! REP+ pra quem me der uma moral nisso ae!
up
up